package cn.edu.nju.ws.sview.wyge.relations.adataset.overview.dataGet;

import java.util.ArrayList;
import java.util.Collections;

public class LeanA {
	public static ArrayList<triple> get(ArrayList<concept> S,
			ArrayList<triple> triples) {
		tripleSort cmp = new tripleSort();
		Collections.sort(triples, cmp);
		ArrayList<triple> A = new ArrayList<triple>();
		for (int i = 0; i < triples.size(); ++i) {
			if ((i == 0)
					|| (cmp.compare(triples.get(i), triples.get(i - 1)) != 0))
				A.add(triples.get(i));
			++A.get(A.size() - 1).w;
		}
		ArrayList<triple> la = new ArrayList<triple>();
		for (int i = 0; i < A.size(); ++i) {
			triple T = A.get(i);
			int j;
			for (j = 0; j < A.size(); ++j) {
				if (i == j)
					continue;
				// if A[i] <= A[j]
				if (A.get(j).partial(S, A.get(j))) {
					break;
				}
				// if A[j] <= A[i]
				if (A.get(i).partial(S, A.get(j))) {
					T.w += A.get(j).w;
				}
			}
			if (j == A.size())
				la.add(T);
		}
		return la;
	}
}
